<?php
namespace Home\Controller;
use Think\Controller;
class RegController extends CommonController {
    public function index(){
    	$question = D('vercode')->getOne();
    	$this->assign('question',$question);
        $this->assign('title',"注册");
        $this->display();
    }
    //异步检测数据，进行注册
    public function checkdata()
    {
    	$this->checkVercode();

        if(I('post.pass')!=I('post.repass')){
            $arr = array(
            'error'=>'1',
            'info'=>'两次密码不一致'
            );
            echo json_encode($arr);
            exit;
        }

        $username= I('post.username');

         $sql = "select * from user where nikename= '{$username}'";

         $res = M()->query($sql);

         if($res){
            $arr = array(
            'error'=>'1',
            'info'=>'用户昵称已存在，请重新写'
            );
            echo json_encode($arr);
            exit;
         }

         $email= I('post.email');

         $sql = "select * from user where email= '{$email}'";

         $res = M()->query($sql);

         if($res){
            $arr = array(
            'error'=>'1',
            'info'=>'用户邮箱已存在，请重新写'
            );
            echo json_encode($arr);
            exit;
         }

         $data = I('post.');

         $data['nikename']=$username;
         $data['password'] = md5($data['pass']);
         $data['create_time'] =time();
         $data['create_ip'] = get_client_ip();

         $data['face'] = "Public/images/face/face_".mt_rand(1,3).".jpg";

         $res = M('user')->add($data);

        if($res){
            $arr = array(
             'error'=>'0',
             'info'=>'注册成功'
             );
        }else{
            $arr = array(
             'error'=>'1',
             'info'=>'注册失败'
             );
        }

    	echo json_encode($arr);
    }
}